package com.colourclash.fruitopia.views 
{
	import com.colourclash.fruitopia.utils.Global;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.DropShadowFilter;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	/**
	 * View to display the current score
	 * 
	 * @author Patrick Hammond
	 */
	public class ScoreView extends Sprite
	{
		private var _scoreTextField:TextField;
		private var _targetScore:int;
		private var _currentScore:int;
		
		public function ScoreView() 
		{
			_currentScore = 0;
			
			var shadow:DropShadowFilter = new DropShadowFilter(0, 0, 0, 1, 3, 3, 7, 1);
			var tf:TextFormat = new TextFormat( "ShowcardGoth", 30 );
			
			_scoreTextField = new TextField;
			_scoreTextField.embedFonts        = true;
			_scoreTextField.selectable		= false;
			_scoreTextField.autoSize          = TextFieldAutoSize.LEFT;
			_scoreTextField.defaultTextFormat = tf;
			_scoreTextField.text              = "0000000";
			_scoreTextField.textColor			= 0xff7601;
			_scoreTextField.filters			= [shadow];
			_scoreTextField.y = 642 * Global.getInstance().getScale();
			_scoreTextField.x = 195  * Global.getInstance().getScale();
			
			this.addChild( _scoreTextField );
			
			addEventListener(Event.ENTER_FRAME, updateScore, false, 0, true);
		}
		
		private function updateScore(e:Event):void 
		{
			if (_currentScore < _targetScore)
			{
				_currentScore += (_targetScore - _currentScore) < 116 ? (_targetScore - _currentScore) : 116;

				var score:String = String(_currentScore);
				_scoreTextField.text = "0000000".substr(0, 8 - score.length) + score;
			}
		}
		
		public function setScore(value:int):void
		{
			_targetScore = value;
			
		}
	}

}